﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;

namespace Painter
{
    public partial class Input : Form
    {
        /// <summary>
        /// 显示文本框中的文本
        /// </summary>
        public static string _txt = "";
        /// <summary>
        /// 
        /// </summary>
        public Input()
        {
            InitializeComponent();
            _txt = @"[2000,1000,4]
[350,200]
[250,150]
[220,300]
[330,250]
#
";
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var ofd = new OpenFileDialog {Filter = "输入文本文件（*.txt）|*.txt"};
            if (ofd.ShowDialog() != DialogResult.OK) return;
            _txt += ReadInput.GetStr(ofd.FileName) + "\r\n#\r\n";
            textBox5.Text = _txt;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var str = textBox5.Text;
            if (!string.IsNullOrEmpty(str))
            {
                ReadInput.ReadCalc(str,ref Form1.Inputs);
                MessageBox.Show("导入计算数据成功！");

            }
            else
            {
                MessageBox.Show("暂无数据！");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            _txt = null;
            textBox5.Text = "";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            var length = textBox1.Text.Trim();
            var width = textBox2.Text.Trim();
            var num = textBox14.Text.Trim();
            if (String.IsNullOrEmpty(length)|| String.IsNullOrEmpty(width) || String.IsNullOrEmpty(num))
            {
                return;
            }
            _txt+= "[" + length + "," + width + "," + num + "]\r\n#\r\n";
            textBox5.Text = _txt;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var dia = textBox3.Text.Trim();
            var dem = textBox4.Text.Trim();
            if (String.IsNullOrEmpty(dia) || String.IsNullOrEmpty(dem))
            {
                return;
            }
            _txt = _txt.Trim('\r','\n','#');
            _txt += "\r\n[" + dia + "," + dem + "]\r\n#\r\n";
            textBox5.Text = _txt;
        }

        private void Input_Load(object sender, EventArgs e)
        {
            textBox5.Text = _txt;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var totalNum = int.Parse(textBox17.Text);
            var len1= int.Parse(textBox9.Text);
            var len2 = int.Parse(textBox10.Text);
            var wid1 = int.Parse(textBox8.Text);
            var wid2 = int.Parse(textBox11.Text);
            var diaNum1= int.Parse(textBox16.Text);
            var diaNum2 = int.Parse(textBox15.Text);
            var dia1= int.Parse(textBox7.Text);
            var dia2 = int.Parse(textBox12.Text);
            var dem1 = int.Parse(textBox6.Text);
            var dem2 = int.Parse(textBox13.Text);
            var ran = new Random();

            for (int i = 0; i < totalNum; i++)
            {
                var length = ran.Next(len1, len2);
                var width = ran.Next(wid1, wid2);
                var num = ran.Next(diaNum1, diaNum2);
                _txt += "[" + length + "," + width + "," + num + "]\r\n";
                for (int j = 0; j < num; j++)
                {
                    var dia = ran.Next(dia1, dia2);
                    var dem = ran.Next(dem1, dem2);
                    _txt += "[" + dia + "," + dem + "]\r\n";
                }
                _txt += "#\r\n";
                textBox5.Text = _txt;
            }
        }
    }
}
